Skip to main content

Lab 24: Change Instance Type Using Terraform

During the migration process, the Nautilus DevOps team created several EC2 instances in different regions. They are currently in the process of identifying the correct resources and utilization and are making continuous changes to ensure optimal resource utilization. Recently, they discovered that one of the EC2 instances was underutilized, prompting them to decide to change the instance type. Please make sure the Status check is completed (if it's still in Initializing state) before making any changes to the instance.

  1. Change the instance type from t2.micro to t2.nano for devops-ec2 instance using terraform.

  2. Make sure the EC2 instance devops-ec2 is in running state after the change.

  3. The Terraform working directory is /home/bob/terraform. Update the main.tf file (do not create a separate .tf file) to change the instance type.

Note: Right-click under the EXPLORER section in VS Code and select Open in Integrated Terminal to launch the terminal.

Create main.tf

# Provision EC2 instance
resource "aws_instance" "ec2" {
ami = "ami-0c101f26f147fa7fd"
instance_type = "t2.nano"
subnet_id = ""
vpc_security_group_ids = [
"sg-5ff802faa142b2739"
]

tags = {
Name = "devops-ec2"
}
}

terraform init
terraform plan -out kke.plan && terraform apply kke.plan
# or apply forcefully without creating plan and applying it
terraform apply -auto-approve


# aws cli
aws secretsmanager get-secret-value --secret-id datacenter-secret --query SecretString